
#include "stm32f10x.h"
#include "board.h"
#include <rtthread.h>
#include "gprs_task.h"
#include <math.h>
#include <rthw.h>
#include "sense.h"

#ifdef RT_USING_RTGUI
#include <..\rtgui\rtgui.h>
#include <../rtgui/rtgui_server.h>
#include <../rtgui/rtgui_system.h>
#include <../rtgui/driver.h>
#include <../rtgui/event.h>
#include <../rtgui/widgets/container.h>
#endif

#include "touch.h"

ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t stack1[ 512 ];
static rt_uint8_t stack2[ 512 ];
static rt_uint8_t adc_stack[ 512 ];


static struct rt_thread thread1;
static struct rt_thread thread2;
static struct rt_thread adc_thread;
  
static rt_timer_t timer1;

extern void adc_thread_entry(void* parameter);

 
static void thread1_entry(void* parameter)
{
    while (1)
    {
			rt_thread_delay( RT_TICK_PER_SECOND/10 );  
    }
}

static void thread2_entry(void* parameter)
{
 	gprs_online();
}

static void timeout1(void * parameter)
{

}

 
int rt_application_init()
{					 	
	rt_err_t result;	
 	
	stm32_rtgui_init();
	rtgui_touch_hw_init();
	
 	result = rt_thread_init(&thread1,
		"thread 1",
		thread1_entry, RT_NULL,
		(rt_uint8_t*)&stack1[0], sizeof(stack1), 20, 5);
	if (result == RT_EOK)
	{
        rt_thread_startup(&thread1);
	}

 	result = rt_thread_init(&thread2,
		"thread 2",
		thread2_entry, RT_NULL,
		(rt_uint8_t*)&stack2[0], sizeof(stack2), 20, 5);
	if (result == RT_EOK)
	{
        rt_thread_startup(&thread2);
	}

    /* init adc thread */
	result = rt_thread_init(&adc_thread,
		"adc",
		adc_thread_entry, RT_NULL,
		(rt_uint8_t*)&adc_stack[0], sizeof(adc_stack), 20, 5);
	if (result == RT_EOK)
	{
        rt_thread_startup(&adc_thread);
	}
  
 	timer1 = rt_timer_create("timer1",
			timeout1,
			RT_NULL,
			RT_TICK_PER_SECOND,
			RT_TIMER_FLAG_PERIODIC	
	);
	if(timer1 != RT_NULL)
		rt_timer_start(timer1);
 	return 0;
}






